package com.bdqn.crm;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.crm.entity.User;
import com.bdqn.crm.mapper.UserMapper;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
public class UserMapperTester {

        @Resource
        private UserMapper userMapper;

        @Test
        public void testSelectById(){
            User user = userMapper.selectById(2L);
            System.out.println("userName:"+user.getUsrname());
        }

        @Test
        public void testInset(){
            userMapper.insert(new User("MyBatis-plus","123456",9L,1));
        }

        @Test
        public void testFindAll(){
            List<User>list=userMapper.selectList(null);
            for(User user:list){
                System.out.println("usrName:"+user.getUsrname());
            }
        }

        @Test
        public void testFind(){
            QueryWrapper<User>wrapper=new QueryWrapper<User>();
            wrapper.eq("usrname","MyBatis-plus");
            wrapper.eq("usr_password","123456");
            List<User>list=userMapper.selectList(wrapper);
            if (list!=null){
                for (User user:list){
                    System.out.println("usrId:"+user.getUsrid());
                }
            }
        }

        @Test
        public void testPagination(){
            QueryWrapper<User>wrapper=new QueryWrapper<User>();
            wrapper.eq("usr_role_id",2L);
            Page<User>page=new Page<>(1,2);
            IPage<User>userPage=userMapper.selectPage(page,wrapper);
            System.out.println("总记录数 ------> " +userPage.getTotal());
            System.out.println("总页数 ------> " +userPage.getPages());
            System.out.println("当前页数 ------> " +(userPage.getCurrent()+1));
            System.out.println("每页记录数 ------> " +userPage.getSize());
            System.out.println("当前页记录数 ------> " +userPage.getSize());
            for (User user : userPage.getRecords()) {
                System.out.println("usrid :"+ user.getUsrid());
        }
     }
}
